<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<!--文件列表模态框-->
<div class="modal fade" id="modal-explain">
    <div class="modal-dialog" style="width: 1240px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">安装完工单</h4>
            </div>
            <div class="modal-body">
                <form id="explainForm" class="form-horizontal" role="form">
                    <div class="row" id="toolbarExplain">
                        <div class="form-inline">
                            <button type="button" id="btn_explainAdd"
                                    class="btn btn-info">
                                上传
                            </button>
                        </div>
                    </div>
                    <div class="row">
                        <table id="bootstrap-table-explain"></table>
                    </div>
                </form>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!--文件上传下载模态框（项目说明）-->
<div class="modal fade" id="modal-uploadExplain">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">上传文件</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-offset-1">
                        <form id="uploadFormExplain" method="post"
                              class="form-horizontal" role="form" enctype="multipart/form-data">
                            <input id="sheetId" type="hidden" name="sheetId">
                            <input id="type" type="hidden" name="type" value="1">
                            <div class="form-group" id="file_group"></div>
                            <div class="form-group">
                                <label for="upload_fileExp">选择附件上传</label>
                                <input id="upload_fileExp" class="btn" type="file" name="file"
                                       style="padding-left: 0px;">
                                <p class="help-block">多个文件请自行打包上传，大小不要超过100M</p>
                            </div>
                            <div class="form-group">
                                <label class="control-label">描述</label>
                                <div class="row">
                                    <div class="col-md-12" style="padding-left: 0px;">
                                        <textarea rows="3" class="form-control" name="remark"
                                                  placeholder="描述"></textarea>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button id="btn-uploadExp" type="button"
                        class="btn btn-success">
                    <span class="Bold">上传</span>
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!--文件描述修改模态框-->
<div class="modal fade" id="modal-updateExplain">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改文件描述</h4>
            </div>
            <div class="modal-body">
                <form id="editFormExplain" class="form-horizontal" role="form">
                    <input id="idFile" type="hidden" name="id">
                    <div class="form-group">
                        <label for="remark" class="col-sm-2 control-label no-padding-right">文件描述</label>
                        <div class="col-sm-10">
                            <textarea class="form-control" id="remark" name="remark" rows="3"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-updateExp">修改</button>
            </div>
        </div>
    </div>
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel" align="center">
                    安装反馈状态维护
                </h4>
            </div>
            <div class="modal-body">
                <form id="partForm" class="form-horizontal" role="form">
                    <input type="hidden" id="id" name="id">
                    <input type="hidden" id="installTime" name="installTime">
                    <input type="hidden" id="installName" name="installName">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">类型 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="special" id="special" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">开始时间 :</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control datepicker" name="installStartTime"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">状态 ：</label>
                        <div class="col-sm-9">
                            <select class="form-control" name="installStatus">
                                <option value="1" selected>未开始</option>
                                <option value="2">执行中</option>
                                <option value="3">已完成</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">结束时间 :</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control datepicker" name="installEndTime"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">备注 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="installDuringRemark" id="sheetForm-installDuringRemark">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="saveMaintain()" id="btn-add">
                    提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<section class="content-header">
    <h1>安装任务查询</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">生产令号</label>
                                    <input id="query-proCode" type="text" name="proCode" class="form-control"
                                           placeholder="请输入生产令号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-installPlace">安装地点</label>
                                    <input id="query-installPlace" type="text" name="installPlace" class="form-control"
                                           placeholder="请输入安装地点">
                                </div>
                                <div class="form-group">
                                    <label for="query-customer">需方</label>
                                    <input id="query-customer" type="text" name="customer" class="form-control"
                                           placeholder="请输入需方">
                                </div>
                                <!--<div class="form-group">-->
                                <!--<label for="query-isinstall">是否需要调试</label>-->
                                <!--<select id="query-isinstall" class="form-control" name="isinstall">-->
                                <!--<option value="" selected>全部</option>-->
                                <!--<option value="1">需要</option>-->
                                <!--<option value="2">不需要</option>-->
                                <!--</select>-->
                                <!--</div>-->
                                <div class="form-group">
                                    <label for="query-installStatu">安装反馈状态</label>
                                    <select id="query-installStatu" class="form-control" name="installStatu">
                                        <option value="" selected>全部</option>
                                        <option value="1">未开始</option>
                                        <option value="2">执行中</option>
                                        <option value="3">已完成</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-startTime">创建日期</label>
                                    <input id="query-startTime" type="text" class="form-control datepicker"
                                           name="startTime"
                                           readonly="readonly"/>
                                    <label for="query-endTime"> 至 </label>
                                    <input id="query-endTime" type="text" class="form-control datepicker" name="endTime"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;
    var tableExplain;
    var statusName = ["不需要", "未开始", "执行中", "已完成"];
    var classType = ["label-primary", " label-default", " label-warning", " label-success"];

    $(function () {

        table = js.table.init({
            url: ctx + "create/dispatching/installList",
            showExport: false,
            detailView: true,
            onExpandRow: function (index, row, $detail) {
                initChildTable(index, row, $detail);
            },
            columns: [
                {
                    title: '序号', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "生产令号", field: 'proCode', width: '100'},
                {title: "项目名称", field: 'proName', width: '280'},
                {title: "订单数量", field: 'prodNum', width: '80'},
                {title: "安装地点", field: 'installPlace', width: '280'},
                {title: "需方", field: 'customer', width: '280'},
                {title: "创建日期", field: 'authorTime', width: '280'},
                {
                    title: "状态", field: 'installStatu', width: '80',
                    formatter: function (value) {
                        return '<span class="badge' + classType[value] + '">' + statusName[value] + '</span>';
                    }
                }
            ]
        });
    });

    initChildTable = function (index, row, $detail) {
        let childTable = $detail.html('<table  style="table-layout:fixed"></table>').find('table');
        $(childTable).bootstrapTable({
            url: ctx + "create/dispatching/installDetail",
            method: 'post',
            sidePagination: "server",
            contentType: "application/x-www-form-urlencoded",
            queryParams: {
                sheetId: row.id,
            },
            responseHandler: function (res) {
                if (res.type === "SUCCESS") {
                    return res.data;
                }
                js.modal.warning(res.msg);
                return {rows: [], total: 0};
            },
            columns: [
                {
                    title: '序号', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    field: 'special',
                    title: '类型'
                },
                {
                    field: 'installStartTime',
                    title: '开始时间'
                },
                {
                    field: 'installStatus',
                    title: '安装进度',
                    formatter: function (value) {
                        return '<span class="badge' + classType[value] + '">' + statusName[value] + '</span>';
                    }
                },
                {
                    field: 'installEndTime',
                    title: '结束时间'
                },
                {
                    field: 'installName',
                    title: '操作者'
                },
                {
                    field: 'installDuringRemark',
                    title: '备注'
                },

                {
                    title: "附件", width: '150',
                    formatter: function (value, row) {
                        let actions = [];
                        actions.push('<span> 文件数:' + row.expCount + '</span> ');

                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="openExplain(' + js.jsonStringify(row) + ')"> 文件</a> ');

                        return actions.join('');
                    }
                }
            ]
        });
    };

    /** 文件附件列表 */
    function initTableExplain(sheetId) {
        // 加载表格
        tableExplain = js.table.init({
            url: ctx + "create/dispatching/installFile",
            id: "bootstrap-table-explain",
            showExport: false,
            pagination: false,
            toolbar: '#toolbarExplain',
            queryData: {
                sheetId: sheetId
            },
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "文件名", field: 'fileName'},
                {title: "内容", field: 'remark'},
                {title: "上传人", field: 'uploadName', width: 100},
                {title: "上传时间", field: 'uploadTime', width: 110},
                {
                    title: "操作", field: 'url', width: 150,
                    formatter: function (value, row) {
                        let actions = [];
                        actions.push('<a class="btn btn-primary btn-xs" href="' + value + '">下载</a> ');
                        return actions.join('');
                    }
                }
            ]
        });
    }

    /** 删除数据项目说明 */
    function delExp(id) {
        js.modal.confirm("确认删除吗？", function () {
            js.post({
                url: ctx + "create/dispatching/delExp",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        // 加载项目说明文件列表
                        js.table.destroy(tableExplain);
                        initTableExplain($("#sheetId").val());
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    /** 打开编辑模态框 */
    function openEditExp(result) {
        $("#idFile").val(result.id);
        $("#remark").val(result.remark);
        js.modal.open("modal-updateExplain");
    }

    /** 修改描述） */
    $("#btn-updateExp").click(function () {
        js.validSubmit({
            formId: "editFormExplain",
            url: ctx + "create/dispatching/updExp",
            data: new FormData($("#editFormExplain")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    // 加载项目说明文件列表
                    js.table.destroy(tableExplain);
                    initTableExplain($("#sheetId").val());
                    js.modal.hide("modal-updateExplain");
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    });
    /** 隐藏模态框（项目说明修改） */
    js.modal.hideEvent("modal-updateExplain", function () {
        js.reset("editFormExplain");
    });
    /** 导入模态框隐藏事件，重置表单，重置验证（项目说明） */
    js.modal.hideEvent("modal-uploadExplain", function () {
        js.reset("uploadFormExplain");
    });
    /** 附件上传（项目说明） */
    $("#btn-uploadExp").click(function () {

        var file = $("#uploadFormExplain [name='file']").get(0).files[0];

        if (!file) {
            js.modal.warning("请选择要上传的文件");
            return;
        }

        if (file) {
            var sizeToMB = (file.size / 1024 / 1024).toFixed(2);
            if (sizeToMB > 100) {
                js.modal.warning("上传文件大小不可超过100MB");
                return;
            }
        }

        js.post({
            url: ctx + "create/dispatching/uploadFileExp",
            data: new FormData($("#uploadFormExplain")[0]),
            contentType: false,
            processData: false,
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success("上传成功！");
                    // 加载项目说明文件列表
                    js.table.destroy(tableExplain);
                    initTableExplain($("#sheetId").val());
                    js.table.refresh(table);
                    js.modal.hide("modal-uploadExplain");
                }
            }
        });
    });
    /** 打开上传模态框（调试附件） */
    $("#btn_explainAdd").click(function () {
        js.modal.open('modal-uploadExplain');
    });

    /** 打开文件附件模态框 */
    function openExplain(row) {
        $("#sheetId").val(row.id);
        // 加载项目说明文件列表
        initTableExplain(row.id);
        js.modal.open("modal-explain");
    }

    /**保存模态框*/
    function saveMaintain() {
        let res = js.vd({
            id: 'partForm',
            notEmpty: ['proCode', 'planTime', 'leader', 'relMan', 'address','installStatus']
        })
        if (!res) {
            return;
        }
        var url = ctx + "create/dispatching/installDetailSave";
        js.validSubmit({
            formId: "partForm",
            url: url,
            data: new FormData($("#partForm")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("myModal");
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });

    }

    /**编辑状态按钮*/
    function edit(row) {

        $("#partForm").fillSpan(row);
        $("#partForm").fillData(row);
        js.modal.open("myModal");
    }
</script>
</body>
</html>
